package com.android.alertdialogtest;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.app.AlertDialog;
import android.content.DialogInterface;

public class AlertDialogTest extends Activity
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button btnQuit = (Button) findViewById (R.id.btnQuit);
        btnQuit.setOnClickListener (new Button.OnClickListener(){
            public void onClick (View v) {
                new AlertDialog.Builder (AlertDialogTest.this)
                .setTitle ("Question")
                .setMessage ("Are you sure that you want to quit?")
                .setIcon(R.drawable.icon)
                .setPositiveButton ("Yes", new DialogInterface.OnClickListener(){
                    public void onClick (DialogInterface dialog, int whichButton){
                        setResult (RESULT_OK);
                        finish ();
                    }
                })
                .setNegativeButton ("No", new DialogInterface.OnClickListener () {
                    public void onClick (DialogInterface dialog, int whichButton) {
                    }
                }) 
                .show ();   
               
            }
        });


        final Button btnTravels = (Button) findViewById (R.id.btnTravels);
        btnTravels.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {   
                new AlertDialog.Builder(AlertDialogTest.this)              
                .setTitle("I want to go to")
                .setItems(R.array.items_indide_dialog,
                    new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichcountry) {
                        String[] travelcountries = 
                            getResources().getStringArray(R.array.items_indide_dialog);                                             
                        new AlertDialog.Builder(AlertDialogTest.this)                        
                        .setMessage("I'm going to " + travelcountries[whichcountry])                        
                        .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                
                            }
                         })
                        .show();
                    }
                 })
               .show();
            }
        });


    }
}
